package com.tencent.org.service.impl;

import com.tencent.basic.util.PageList;
import com.tencent.org.domain.Detail;
import com.tencent.org.mapper.DetailMapper;
import com.tencent.org.query.DetailQuery;
import com.tencent.org.service.DetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DetailServiceImpl implements DetailService {
    // 注入DepartmentMapper对象
    @Autowired
    private DetailMapper detailMapper;

    @Override
    @Transactional
    public void del(Long id) {
        detailMapper.del(id);
    }

    @Override
    @Transactional
    public void add(Detail detail) {
        detailMapper.add(detail);
    }

    @Override
    @Transactional
    public void update(Detail detail) {
        detailMapper.update(detail);
    }

    @Override
    public List<Detail> findAll() {
        return detailMapper.findAll();
    }

    @Override
    public Detail findById(Long id) {
        return detailMapper.findById(id);
    }

    @Override
    public PageList<Detail> queryPage(DetailQuery detailQuery) {
        // 查询数据的总条数
        Integer totals = detailMapper.queryCount(detailQuery);
        if (totals == 0){
            return new PageList<>();
        }
        // 查询当前页的数据
        List<Detail> data = detailMapper.queryData(detailQuery);
        return new PageList<>(data, totals);

    }

    @Override
    public void patchDel(List<Long> ids) {
        detailMapper.patchDel(ids);
    }
}
